package com.heihei.authority.core.validate.code.sms;

import com.heihei.authority.core.properties.FeiSecurityConstants;
import com.heihei.authority.core.validate.code.ValidateCode;
import com.heihei.authority.core.validate.code.impl.AbstractValidateCodeProcessor;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.context.request.ServletWebRequest;

import javax.annotation.Resource;

/**
 *  短信验证码处理器
 *
 * @version 1.0
 * @since JDK1.8
 * @author duanhengfei
 * @date 2021年04月12日 11:15:05
 */
@Component("smsValidateCodeProcessor")
public class SmsCodeProcessor extends AbstractValidateCodeProcessor<ValidateCode> {

	/**
	 * 短信验证码发送器
	 */
	@Resource
	private SmsCodeSender smsCodeSender;
	
	@Override
	protected void send(ServletWebRequest request, ValidateCode validateCode) throws Exception {
		String mobile = ServletRequestUtils.getRequiredStringParameter(request.getRequest(), FeiSecurityConstants.DEFAULT_PARAMETER_NAME_MOBILE);
		smsCodeSender.send(mobile, validateCode.getCode());
	}

}
